<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;

class DingTalkMessage extends BaseModel
{
    use HasFactory;
    protected $table = 'dingtalk_message';
    protected $guarded = [];
    public function dingTalkApp()
    {
        return $this->belongsTo(DingTalkApp::class, "app_id");
    }
    public function scopeRelatedJoin($query)
    {
        $query->addSelect($this->getTable() . ".*");
        $query->leftjoin((new DingTalkApp)->getTable() . " as DingTalkApp", function ($join) {
            $join->on($this->getTable() . ".app_id", '=', "DingTalkApp.id");
        })->addSelect("DingTalkApp.name as app_name");

        return $query;
    }
}
